package com.eunion.core.exception;

import org.springframework.core.NestedRuntimeException;

/**
 * 主要的异常.
 * 
 * 
 * @version 2015-4-17
 * 
 *  merge from springside project
 * @version 2015-05-24
 */
public class ProjectException extends NestedRuntimeException {

    private static final long serialVersionUID = 7425277866194260414L;
    
    public ProjectException(String msg) {
        super(msg);
    }

    public ProjectException(String msg, Throwable throwable) {
        super(msg, throwable);
    }

    /**
     * 将CheckedException转换为UncheckedException.
     */
    public RuntimeException unchecked(Throwable ex) {
        return ExceptionUtil.unchecked(ex);
    }

    /**
     * 将ErrorStack转化为String.
     */
    public String getStackTraceAsString(Throwable ex) {
        return ExceptionUtil.getStackTraceAsString(ex);
    }

    /**
     * 获取组合本异常信息与底层异常信息的异常描述, 适用于本异常为统一包装异常类，底层异常才是根本原因的情况。
     */
    public String getErrorMessageWithNestedException(Throwable ex) {
        return ExceptionUtil.getErrorMessageWithNestedException(ex);
    }

    /**
     * 获取异常的Root Cause.
     */
    public Throwable getRootCause(Throwable ex) {
        return ExceptionUtil.getRootCause(ex);
    }

    /**
     * 判断异常是否由某些底层的异常引起.
     */
    @SuppressWarnings("unchecked")
    public boolean isCausedBy(Exception ex, Class<? extends Exception>... causeExceptionClasses) {
        return ExceptionUtil.isCausedBy(ex, causeExceptionClasses);
    }
}
